/**
 * 渠道发布，发布记录与获取记录
 */
import React from 'react';
import { history } from 'umi'
import { PageContainer } from '@/molecules';
import { HistoryTotal } from './containers';

const tabList = [
    {
        key: '1',
        tab: '岗位发布记录'
    },
    {
        key: '2',
        tab: '简历获取记录'
    }
];

const History = ({ location }) => {
    const { query } = location;
    const [activeKey, setActiveKey] = React.useState('1');
    const [savedQuery, setSavedQuery] = React.useState(null);

    const handleTabChange = key => {
        setActiveKey(key);
        const obj = {};
        if (query?.channelCompanyCode) {
            obj.channelCompanyCode = query.channelCompanyCode;
        }
        history.push({ query: { ...savedQuery?.[key], ...obj, activeKey: key } });
    };

    const CONTENT = {
        1: <HistoryTotal type="publish" key="publish" />,
        2: <HistoryTotal type="resume" key="resume" />
    };

    React.useEffect(() => {
        const key = query?.activeKey || '1';
        setActiveKey(key);
        setSavedQuery({
            ...savedQuery,
            [key]: query
        });
    }, [query]);

    return (
        <PageContainer tabList={tabList} activeTabKey={activeKey} onTabChange={handleTabChange}>
            {CONTENT[activeKey]}
        </PageContainer>
    );
};

export default History;
